module.exports = app => {
    const { STRING, INTEGER, DATE, BIGINT, TEXT } = app.Sequelize;
    const Commodity = app.model.define("commodity", {
        id: {
            type: BIGINT(11),
            autoIncrement: true,
            primaryKey: true,
            unique: true
        },
        tag: BIGINT, // 小标签
        type_id: BIGINT(11), // 种类ID
        name: STRING(30), // 标题
        introduction: TEXT, //  简介
        introduce: TEXT, // 介绍
        price: BIGINT, // 价格
        oldprice: BIGINT, // 原价格
        cover: STRING, // 封面
        folder: STRING(30), // 归属文件夹
        specifications: TEXT, //  规格
        collection: {
            type: BIGINT,
            defaultValue: 0
        }, // 收藏数量
        status: {
            type: INTEGER,
            defaultValue: 1
        },
        created_at: DATE,
        updated_at: DATE
    }, {
        timestamps: true, // 自动维护时间戳 [ created_at、updated_at ]
        createdAt: 'created_at',
        updatedAt: 'updated_at',
        deletedAt: false, // 'deleted_at',
        paranoid: false
    });
    Commodity.associate = () => {
        app.model.ModCommodity.belongsTo(app.model.ModType, {
            as: 'type',
            foreignKey: 'type_id',
            targetKey: 'id'
        });
    }
    // Commodity.sync({ force: true });

    return Commodity;
};